home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri K-CD 2002 #1 / K-CD_2002-01.iso / Delphi / INSTALL / program files / Borland / Delphi6 / Doc / Registry.int < prev    next >
Encoding:
Text File  |  2001-05-22  |  7.2 KB  |  148 lines

  1. { *********************************************************************** }
  2. {                                                                         }
  3. { Delphi Runtime Library                                                  }
  4. {                                                                         }
  5. { Copyright (c) 1995-2001 Borland Software Corporation                    }
  6. {                                                                         }
  7. { *********************************************************************** }
  8.  
  9. unit Registry;
  10.  
  11. {$R-,T-,H+,X+}
  12.  
  13. interface
  14.  
  15. uses {$IFDEF LINUX} WinUtils, {$ENDIF} Windows, Classes, SysUtils, IniFiles;
  16.  
  17. type
  18.   ERegistryException = class(Exception);
  19.  
  20.   TRegKeyInfo = record
  21.     NumSubKeys: Integer;
  22.     MaxSubKeyLen: Integer;
  23.     NumValues: Integer;
  24.     MaxValueLen: Integer;
  25.     MaxDataLen: Integer;
  26.     FileTime: TFileTime;
  27.   end;
  28.  
  29.   TRegDataType = (rdUnknown, rdString, rdExpandString, rdInteger, rdBinary);
  30.  
  31.   TRegDataInfo = record
  32.     RegData: TRegDataType;
  33.     DataSize: Integer;
  34.   end;
  35.  
  36.   TRegistry = class(TObject)
  37.   protected
  38.     procedure ChangeKey(Value: HKey; const Path: string);
  39.     function GetBaseKey(Relative: Boolean): HKey;
  40.     function GetData(const Name: string; Buffer: Pointer;
  41.       BufSize: Integer; var RegData: TRegDataType): Integer;
  42.     function GetKey(const Key: string): HKEY;
  43.     procedure PutData(const Name: string; Buffer: Pointer; BufSize: Integer; RegData: TRegDataType);
  44.     procedure SetCurrentKey(Value: HKEY);
  45.   public
  46.     constructor Create; overload;
  47.     constructor Create(AAccess: LongWord); overload;
  48.     destructor Destroy; override;
  49.     procedure CloseKey;
  50.     function CreateKey(const Key: string): Boolean;
  51.     function DeleteKey(const Key: string): Boolean;
  52.     function DeleteValue(const Name: string): Boolean;
  53.     function GetDataInfo(const ValueName: string; var Value: TRegDataInfo): Boolean;
  54.     function GetDataSize(const ValueName: string): Integer;
  55.     function GetDataType(const ValueName: string): TRegDataType;
  56.     function GetKeyInfo(var Value: TRegKeyInfo): Boolean;
  57.     procedure GetKeyNames(Strings: TStrings);
  58.     procedure GetValueNames(Strings: TStrings);
  59.     function HasSubKeys: Boolean;
  60.     function KeyExists(const Key: string): Boolean;
  61.     function LoadKey(const Key, FileName: string): Boolean;
  62.     procedure MoveKey(const OldName, NewName: string; Delete: Boolean);
  63.     function OpenKey(const Key: string; CanCreate: Boolean): Boolean;
  64.     function OpenKeyReadOnly(const Key: String): Boolean;
  65.     function ReadCurrency(const Name: string): Currency;
  66.     function ReadBinaryData(const Name: string; var Buffer; BufSize: Integer): Integer;
  67.     function ReadBool(const Name: string): Boolean;
  68.     function ReadDate(const Name: string): TDateTime;
  69.     function ReadDateTime(const Name: string): TDateTime;
  70.     function ReadFloat(const Name: string): Double;
  71.     function ReadInteger(const Name: string): Integer;
  72.     function ReadString(const Name: string): string;
  73.     function ReadTime(const Name: string): TDateTime;
  74.     function RegistryConnect(const UNCName: string): Boolean;
  75.     procedure RenameValue(const OldName, NewName: string);
  76.     function ReplaceKey(const Key, FileName, BackUpFileName: string): Boolean;
  77.     function RestoreKey(const Key, FileName: string): Boolean;
  78.     function SaveKey(const Key, FileName: string): Boolean;
  79.     function UnLoadKey(const Key: string): Boolean;
  80.     function ValueExists(const Name: string): Boolean;
  81.     procedure WriteCurrency(const Name: string; Value: Currency);
  82.     procedure WriteBinaryData(const Name: string; var Buffer; BufSize: Integer);
  83.     procedure WriteBool(const Name: string; Value: Boolean);
  84.     procedure WriteDate(const Name: string; Value: TDateTime);
  85.     procedure WriteDateTime(const Name: string; Value: TDateTime);
  86.     procedure WriteFloat(const Name: string; Value: Double);
  87.     procedure WriteInteger(const Name: string; Value: Integer);
  88.     procedure WriteString(const Name, Value: string);
  89.     procedure WriteExpandString(const Name, Value: string);
  90.     procedure WriteTime(const Name: string; Value: TDateTime);
  91.     property CurrentKey: HKEY;
  92.     property CurrentPath: string;
  93.     property LazyWrite: Boolean;
  94.     property RootKey: HKEY;
  95.     property Access: LongWord;
  96.   end;
  97.  
  98.   TRegIniFile = class(TRegistry)
  99.   public
  100.     constructor Create(const FileName: string); overload;
  101.     constructor Create(const FileName: string; AAccess: LongWord); overload;
  102.     function ReadString(const Section, Ident, Default: string): string;
  103.     function ReadInteger(const Section, Ident: string;
  104.       Default: Longint): Longint;
  105.     procedure WriteInteger(const Section, Ident: string; Value: Longint);
  106.     procedure WriteString(const Section, Ident, Value: String);
  107.     function ReadBool(const Section, Ident: string; Default: Boolean): Boolean;
  108.     procedure WriteBool(const Section, Ident: string; Value: Boolean);
  109.     procedure ReadSection(const Section: string; Strings: TStrings);
  110.     procedure ReadSections(Strings: TStrings);
  111.     procedure ReadSectionValues(const Section: string; Strings: TStrings);
  112.     procedure EraseSection(const Section: string);
  113.     procedure DeleteKey(const Section, Ident: String);
  114.     property FileName: string;
  115.   end;
  116.  
  117.   TRegistryIniFile = class(TCustomIniFile)
  118.   public
  119.     constructor Create(const FileName: string); overload;
  120.     constructor Create(const FileName: string; AAccess: LongWord); overload;
  121.     destructor Destroy; override;
  122.     function ReadDate(const Section, Name: string; Default: TDateTime): TDateTime; override;
  123.     function ReadDateTime(const Section, Name: string; Default: TDateTime): TDateTime; override;
  124.     function ReadInteger(const Section, Ident: string; Default: Longint): Longint; override;
  125.     function ReadFloat(const Section, Name: string; Default: Double): Double; override;
  126.     function ReadString(const Section, Ident, Default: string): string; override;
  127.     function ReadTime(const Section, Name: string; Default: TDateTime): TDateTime; override;
  128.     function ReadBinaryStream(const Section, Name: string; Value: TStream): Integer; override;
  129. //    procedure ReadKeys(const Section: string; Sections: TStrings);
  130.     procedure WriteDate(const Section, Name: string; Value: TDateTime); override;
  131.     procedure WriteDateTime(const Section, Name: string; Value: TDateTime); override;
  132.     procedure WriteFloat(const Section, Name: string; Value: Double); override;
  133.     procedure WriteInteger(const Section, Ident: string; Value: Longint); override;
  134.     procedure WriteString(const Section, Ident, Value: String); override;
  135.     procedure WriteTime(const Section, Name: string; Value: TDateTime); override;
  136.     procedure WriteBinaryStream(const Section, Name: string; Value: TStream); override;
  137.     procedure ReadSection(const Section: string; Strings: TStrings); override;
  138.     procedure ReadSections(Strings: TStrings); override;
  139.     procedure ReadSectionValues(const Section: string; Strings: TStrings); override;
  140.     procedure EraseSection(const Section: string); override;
  141.     procedure DeleteKey(const Section, Ident: String); override;
  142.     procedure UpdateFile; override;
  143.  
  144.     property RegIniFile: TRegIniFile;
  145.   end;
  146.  
  147. implementation
  148.